package cn.fu.algorithm;

/**
 * @Title: GenericPrivilegeBase.java
 * @Package com.viewhigh.yhrpweb.web.sys.service.impl
 * @Description: 超递增序列-背包(用于权限)
 * @author zhangxiaofu
 * @Company www.viewhigh.com
 * @date 2016年7月25日 下午2:22:37
 * @version V1.0
 */
public class GenericPrivilegeBase {
    public final static int NO_PRIVILEGE = 0;
    public final static int QUERY_OR_USE_PRIVILEGE = 1;// 察看权限
    public final static int CREATE_PRIVILEGE = 2;// 添加权限
    public final static int DELETE_PRIVILEGE = 4;// 删除权限
    public final static int UPDATE_PRIVILEGE = 8;// 更新权限
    public final static int ALL_PRIVILEGE = QUERY_OR_USE_PRIVILEGE | CREATE_PRIVILEGE | DELETE_PRIVILEGE
            | UPDATE_PRIVILEGE;// 增删改查权限

    public GenericPrivilegeBase() {
    }

    public static boolean isValidPrivilege(int privilege)// 判断是否具有权限
    {
        if ((privilege & QUERY_OR_USE_PRIVILEGE) != 0) {
            return true;
        }

        if ((privilege & CREATE_PRIVILEGE) != 0) {
            return true;
        }

        if ((privilege & DELETE_PRIVILEGE) != 0) {
            return true;
        }

        if ((privilege & UPDATE_PRIVILEGE) != 0) {
            return true;
        }

        return false;
    }

    public static boolean checkQueryPrivilege(int privilege)// 判断是否具有察看权限
    {
        if ((privilege & QUERY_OR_USE_PRIVILEGE) != 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean checkUsePrivilege(int privilege) {
        if ((privilege & QUERY_OR_USE_PRIVILEGE) != 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean checkCreatePrivilege(int privilege)// 判断是否有添加权限
    {
        if ((privilege & CREATE_PRIVILEGE) != 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean checkDeletePrivilege(int privilege)// 判断是否有删除权限
    {
        if ((privilege & DELETE_PRIVILEGE) != 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean checkUpdatePrivilege(int privilege) {
        if ((privilege & UPDATE_PRIVILEGE) != 0) {
            return true;
        } else {
            return false;
        }
    }
    
    
    public static void main(String[] args) {
        GenericPrivilegeBase base = new GenericPrivilegeBase();
        boolean privilege = base.isValidPrivilege(15);
        System.err.println(privilege);
    }
}
